// ===========================================切片==========================================
#[test]
fn test_firstword() {
    let mut s = String::from("hello world");
    let word = first_word(&s);
    s.clear();
    println!("'{}' {}",s, word)
}

fn first_word(s: &String) -> usize {
    let bytes = s.as_bytes();
    for (i, &item) in bytes.iter().enumerate() {
        if item == b' ' {
            return i
        }
    }

    return bytes.len()
}

// 字符串slice
#[test]
fn test_string_slice() {
    let s = String::from("hello world");
    let word = first_word_slice(&s);
    println!("'{}' {}",s, word)
}

fn first_word_slice(s: &String) -> &str{
    let bytes = s.as_bytes();
    for (i, &item) in bytes.iter().enumerate() {
        if item == b' ' {
            return &s[..i]
        }
    }
    return &s[..s.len()]
}

// int slice
#[test]
fn test_int_arr(){
    let list = ["james", "jack", "jim", "holly"];
    let _ = &list[..3].iter()
        .filter(|s|s.len()>3)
        .for_each(|x|println!("{}", x));
}
